package com.team2.insulatingtools.modular.tools.controller;

import com.team2.insulatingtools.modular.tools.dto.ToolDetailQueriedDto;
import com.team2.insulatingtools.modular.tools.entity.ToolDetail;
import com.team2.insulatingtools.modular.tools.entity.Tools;
import com.team2.insulatingtools.modular.tools.pojo.request.MultipleToolDetailRequest;
import com.team2.insulatingtools.modular.tools.pojo.request.ToolDetailAddRequest;
import com.team2.insulatingtools.modular.tools.pojo.request.ToolDetailPageRequest;
import com.team2.insulatingtools.modular.tools.pojo.request.ToolDetailRequest;
import com.team2.insulatingtools.modular.tools.pojo.request.*;
import com.team2.insulatingtools.modular.tools.service.ToolDetailService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 工具详细信息 控制器
 *
 * @author team2
 * @date 2023/04/03 09:48
 */
@RestController
@ApiResource(name = "工具详细信息 ")
public class ToolDetailController {

    @Resource
    private ToolDetailService toolDetailService;

//    /**
//     * 添加
//     *
//     * @author team2
//     * @date 2023/04/03 09:48
//     */
//    @PostResource(name = "添加", path = "/toolDetail/add")
//    public ResponseData<ToolDetail> add(@RequestBody @Validated(ToolDetailRequest.add.class) ToolDetailRequest toolDetailRequest) {
//        toolDetailService.add(toolDetailRequest);
//        return new SuccessResponseData<>();
//    }

    /**
     * 删除
     *
     * @author team2
     * @date 2023/04/03 09:48
     */
    @PostResource(name = "删除", path = "/toolDetail/delete")
    public ResponseData<?> delete(@RequestBody @Validated(ToolDetailRequest.delete.class) ToolDetailRequest toolDetailRequest) {
        toolDetailService.del(toolDetailRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑
     *
     * @author team2
     * @date 2023/04/03 09:48
     */
    @PostResource(name = "编辑", path = "/toolDetail/edit")
    public ResponseData<?> edit(@RequestBody @Validated(ToolDetailRequest.edit.class) ToolDetailRequest toolDetailRequest) {
        toolDetailService.edit(toolDetailRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑
     *
     * @author team2
     * @date 2023/04/03 09:48
     */
    @PostResource(name = "编辑", path = "/toolDetail/editBatch")
    public ResponseData<?> editBatch(@RequestBody ToolDetailRequest toolDetailRequest) {
        toolDetailService.updateBatch(toolDetailRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 查看详情
     *
     * @author team2
     * @date 2023/04/03 09:48
     */
    @GetResource(name = "查看详情", path = "/toolDetail/detail")
    public ResponseData<ToolDetail> detail(@Validated(ToolDetailRequest.detail.class) ToolDetailRequest toolDetailRequest) {
        return new SuccessResponseData<>(toolDetailService.detail(toolDetailRequest));
    }

    /**
     * 获取列表
     *
     * @author team2
     * @date 2023/04/03 09:48
     */
    @GetResource(name = "获取列表", path = "/toolDetail/list")
    public ResponseData<List<ToolDetail>> list(ToolDetailRequest toolDetailRequest) {
        return new SuccessResponseData<>(toolDetailService.findList(toolDetailRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author team2
     * @date 2023/04/03 09:48
     */
    @GetResource(name = "分页查询", path = "/toolDetail/page")
    public ResponseData<PageResult<ToolDetail>> page(ToolDetailRequest toolDetailRequest) {
        return new SuccessResponseData<>(toolDetailService.findPage(toolDetailRequest));
    }

    /**
     * 根据多个ToolDetail对象id更新ToolDetail和Tools
     */
    @PostResource(name = "根据多个ToolDetail对象id更新ToolDetail和Tools", path = "/toolDetail/updateMultipleToolsUsingMultipleToolDetails")
    public ResponseData<List<Tools>> updateMultipleToolsUsingMultipleToolDetails(@RequestBody MultipleToolDetailRequest multipleToolDetailRequest) {
        return new SuccessResponseData<>(toolDetailService.updateMultipleToolsUsingMultipleToolDetails(multipleToolDetailRequest));
    }

    /**
     * 根据workshopId和itemId进行查询，并且分页
     * workshopId: 表示车间号
     * item: 表示物品编号
     * curr: 表示当前页码
     * size: 表示每一页有多少条数据
     */
    @GetResource(name = "传入workshopId和toolId，进行查询", path = "/toolDetail/pageByWorkshopAndTool")
    public ResponseData<List<ToolDetailQueriedDto>> pageByWorkshopAndTool(ToolDetailPageRequest toolDetailPageRequest) {
        return new SuccessResponseData<>(toolDetailService.pageByWorkshopAndTool(toolDetailPageRequest.getWorkshopName(),
                toolDetailPageRequest.getToolName(),
                toolDetailPageRequest.getPageNo(),
                toolDetailPageRequest.getPageSize()));
    }
    /**
     * 添加具体信息（分节）
     *
     * @author team2
     * @date 2023/04/03 09:48
     */
    @PostResource(name = "添加具体信息（分节）", path = "/api/toolDetail/add")
    public ResponseData<?> add(@RequestBody ToolDetailAddRequest request) {
        return toolDetailService.addToolsDetail(request);
    }
    /**
     * 删除具体信息（分节）
     *
     * @author team2
     * @date 2023/04/03 09:48
     */
    @GetResource(name = "删除具体信息（分节）", path = "/api/toolDetail/del")
    public ResponseData<?> del(int id) {
        return toolDetailService.delToolsDetail(id);
    }

    /**
     * 查找子分节
     *
     * @author team2
     * @date 2023/04/03 09:48
     */
    @GetResource(name = "查询子分节", path = "/api/toolDetail/selbytid")
    public ResponseData<?> selByTid(int tid) {
        return toolDetailService.selByTid(tid);
    }

    /**
     * 根据tid获取列表（带分页）
     *
     * @author team2
     * @date 2023/04/03 09:48
     */
    @GetResource(name = "分页查询", path = "/api/toolDetail/pagebytid")
    public ResponseData<?> pageByTid(int tid,int page,int size) {
        return new SuccessResponseData<>(toolDetailService.pageByTid(tid,page,size));
    }
}
